package model.eval;

import enums.TestPanelEnum;
import enums.TextBundleEnum;
import enums.URLEnum;
import enums.VennEnum;
import misc.BundlesProvider;
import model.Sylogism;
import model.Venn;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Ejercicio de diagramas de Venn;
 *
 * @author Jose Martin Rozanec;
 */
public class TestExerciseVenn extends TestExcercise{
    /**
     * Constructor;
     */
    public TestExerciseVenn() {
        this.panelEnum = TestPanelEnum.VENN;
    }

    public int getAchievedScore() {
        if(Venn.isCorrect((VennEnum[])getStudentsSolution(),(Sylogism)getExcerciseData())){
            return getCorrectScore();
        } else {
            return getIncorrectScore();
        }
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.DIAGRAMAS_VENN.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]");
        buffer.append("\n" + ((Sylogism) getExcerciseData()).toString());
        VennEnum[] solution = Venn.analizeSylogism((Sylogism) getExcerciseData());
        for(int j=0;j<7;j++){
            buffer.append("\n "+(j+1) + " - " + translateVennEnum(solution[j]));
        }
        return buffer.toString();
    }

    private String translateVennEnum(VennEnum vennEnum){
        switch (vennEnum){
            case CROSS:
                return vennEnum.toString();
            case FILL:
                return vennEnum.toString();
            case NOTHING:
                return vennEnum.toString();
        }
        return "";
    }

    public String getStudentSolutionString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.DIAGRAMAS_VENN.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]");
        buffer.append("\n" + ((Sylogism) getExcerciseData()).toString());
        System.out.println(""+getStudentsSolution());//todo delete
        VennEnum[] solution = (VennEnum[]) getStudentsSolution();
        buffer.append("\n");
        for(int j=0;j<4;j++){
            buffer.append("\t "+(j+1) + " - " + translateVennEnum(solution[j]));
        }
        buffer.append("\n");
        for(int j=4;j<7;j++){
            buffer.append("\t "+(j+1) + " - " + translateVennEnum(solution[j]));
        }
        return buffer.toString();
    }
}
